package com.emokili.ewa.frame.controller.v1;

import com.emokili.ewa.common.utils.R;
import com.emokili.ewa.core.frame.entity.PlayListEntity;
import com.emokili.ewa.core.frame.entity.PlayListImageEntity;
import com.emokili.ewa.core.frame.service.PlayListImageService;
import com.emokili.ewa.core.frame.service.PlayListService;
import com.emokili.ewa.core.frame.service.PlayListSettingService;
import com.emokili.ewa.core.frame.vo.PlayListActiveVo;
import com.emokili.ewa.core.frame.vo.PlayListAddVo;
import com.emokili.ewa.core.frame.vo.PlayListSettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yuepanpan
 */
@RestController
@RequestMapping("v1/frame/playlists")
public class PlayListController {

    @Autowired
    private PlayListService playListService;
    @Autowired
    private PlayListImageService playListImageService;

    @Autowired
    private PlayListSettingService playListSettingService;

    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody PlayListActiveVo playListActiveVo){
        playListService.changeActiveStatus(playListActiveVo);
        return R.ok();
    }

    /**
     * 相册设置
     * @param playListSettingVo
     * @return
     */
    @PostMapping("/settings")
    @ResponseBody
    public R settings(@RequestBody PlayListSettingVo playListSettingVo){
        playListSettingService.update(playListSettingVo);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Long id){
        playListService.deletePlayList(id);
        return R.ok();
    }

    @PostMapping("/add")
    @ResponseBody
    public R add(@RequestBody PlayListAddVo playListAddVo){
        playListService.createPlayList(playListAddVo);
        return R.ok();
    }

    @GetMapping("/home")
    @ResponseBody
    public R homePage(@RequestParam String serialNumber){
        Boolean aBoolean = playListService.enterHome(serialNumber);
        return R.ok().setData(aBoolean);
    }

    @GetMapping("/playlists")
    @ResponseBody
    public R playList(@RequestParam String serialNumber){
        List<PlayListEntity> playListEntityList = playListService.listPlayLists(serialNumber);
        return R.ok().put("playList",playListEntityList);
    }

    @RequestMapping("/playlist/{playlistId}")
    @ResponseBody
    public R listImages(@PathVariable String playlistId){
        List<PlayListImageEntity> playListImageEntities = playListImageService.listImages(playlistId);
        return R.ok().put("playListImageList",playListImageEntities);
    }
}
